package edu.ynu.se.xiecheng.achitectureclass.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyAdvice {
    private Logger logger = LoggerFactory.getLogger(MyAdvice.class);

    // 定义切入点
    @Before("execution(* edu.ynu.se.xiecheng.achitectureclass.controller..*.*(..))")
    public void logBeforeControllerMethod(JoinPoint joinPoint) {
        String methodName = joinPoint.getSignature().getName();
        String className = joinPoint.getTarget().getClass().toString();
        logger.info("调用方法：" + className + "." + methodName);
    }

    @After("execution(* edu.ynu.se.xiecheng.achitectureclass.controller..*.*(..))")
    public void logAfterControllerMethod(JoinPoint joinPoint) {
        String methodName = joinPoint.getSignature().getName();
        String className = joinPoint.getTarget().getClass().toString();
        logger.info("方法调用结束：" + className + "." + methodName);
    }
}
